package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.SysProject;
import com.ruoyi.system.domain.params.SysProjectParams;
import com.ruoyi.system.mapper.SysProjectMapper;
import com.ruoyi.system.service.ISysProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目Service业务层处理
 *
 * @author liuxing
 * @date 2021-02-03
 */
@Service
public class SysProjectServiceImpl implements ISysProjectService {
    @Autowired
    private SysProjectMapper sysProjectMapper;


    /**
     * 查询项目
     *
     * @param id 项目ID
     * @return 项目
     */
    @Override
    public SysProject selectSysProjectById(Long id) {
        return sysProjectMapper.selectSysProjectById(id);
    }

    /**
     * 查询项目列表
     *
     * @param sysProjectParams 项目
     * @return 项目
     */
    @Override
    public List<SysProject> selectSysProjectList(SysProjectParams sysProjectParams) {
        return sysProjectMapper.selectSysProjectList(sysProjectParams);
    }

    /**
     * 新增项目
     *
     * @param sysProject 项目
     * @return 结果
     */
    @Override
    public int insertSysProject(SysProject sysProject) {
        sysProject.setCreateBy(SecurityUtils.getUsername());
        sysProject.setCreateTime(DateUtils.getNowDate());
        sysProject.setUpdateBy(SecurityUtils.getUsername());
        sysProject.setUpdateTime(DateUtils.getNowDate());
        return sysProjectMapper.insertSysProject(sysProject);
    }

    /**
     * 修改项目
     *
     * @param sysProject 项目
     * @return 结果
     */
    @Override
    public int updateSysProject(SysProject sysProject) {
        sysProject.setUpdateBy(SecurityUtils.getUsername());
        sysProject.setUpdateTime(DateUtils.getNowDate());
        return sysProjectMapper.updateSysProject(sysProject);
    }

    /**
     * 批量删除项目
     *
     * @param ids 需要删除的项目ID
     * @return 结果
     */
    @Override
    public int deleteSysProjectByIds(Long[] ids) {
        return sysProjectMapper.deleteSysProjectByIds(ids);
    }

    /**
     * 删除项目信息
     *
     * @param id 项目ID
     * @return 结果
     */
    @Override
    public int deleteSysProjectById(Long id) {
        return sysProjectMapper.deleteSysProjectById(id);
    }

    /**
     * 启用项目
     *
     * @param id 项目ID
     * @return 结果
     */
    @Override
    public int enableSysProject(Long id) {
        SysProject sysProject = new SysProject();
        sysProject.setId(id);
        sysProject.setStatus("0");
        return sysProjectMapper.updateSysProject(sysProject);
    }

    /**
     * 停用项目
     *
     * @param id 项目ID
     * @return 结果
     */
    @Override
    public int stopSysProject(Long id) {
        SysProject sysProject = new SysProject();
        sysProject.setId(id);
        sysProject.setStatus("1");
        return sysProjectMapper.updateSysProject(sysProject);
    }
}
